package com.shiro.controller;


import com.shiro.config.JwtUtil;
import com.shiro.pojo.UserBean;
import com.shiro.serivce.UserSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RestController
@Slf4j
public class MyControoler {

    @Autowired
            private UserSerivce userSerivce;



    @RequestMapping("/login")
    public Object login(String username ,String password,Model model){
        Map<String,Object> map=new ConcurrentHashMap<>();
        UserBean userBean=new UserBean();
        userBean.setPassword(password);
        userBean.setUsername(username);
        if(userSerivce.findByUsernamaPassword(username,password)!=null){
            String jwt = JwtUtil.createJWT(100000, userBean);
             map.put("token:",jwt);
             return map;
        }
        map.put("msg","生成失败");
        return map;
    }
    @RequestMapping("/tologin")
    @ResponseBody
   public String uanth(){
        return "请登录了才访问数据!";
    }


    @GetMapping("info")
     public Object inff(String token){
        return JwtUtil.verify(token);
    }
}